package servlet.Visitor;

import domain.Info;
import domain.Room;
import domain.Visitors;
import service.person.PersonService;
import service.person.PersonServiceImpl;
import service.visitor.VisitorService;
import service.visitor.VisitorServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

public class VisitorInfo extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

        if(request.getSession().getAttribute("userloginflag")==null){
            request.getRequestDispatcher("/index.jsp").forward(request, response);
        }
        else {
            Room room = (Room)request.getSession().getAttribute("userloginflag");
            VisitorService visitorService = new VisitorServiceImpl();
            ArrayList<Visitors> list = visitorService.getVisitors(room.getRoom_id());
            request.setAttribute("list", list);
            if (request.getAttribute("message") != null) {
                request.setAttribute("message", request.getAttribute("message"));
            }
            request.getRequestDispatcher("/app/visitor/index.jsp").forward(request, response);
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}
